﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Ivory.Interface
{
    public abstract class GUIPanel : GUIComponent
    {
        //Fields
        protected Dictionary<string, GUIComponent> _ComponentList;

                //cTor
        public GUIPanel(Rectangle ClickRectangle)
            : base(ClickRectangle)
        {
            _ComponentList = new Dictionary<string, GUIComponent>();
            Init();
        }

        //Methods
        protected abstract void Init();

        protected void AddComponent(GUIComponent component)
        {
            if (component.ID == null)
                throw new IvoryFrameworkError(Errors.ComponentHasNoID);

            if (_ComponentList.ContainsKey(component.ID))
                throw new IvoryFrameworkError(Errors.ComponentNameNotUnique(component.ID));

            _ComponentList.Add(component.ID, component);
        }
        protected void RemoveComponent(string key)
        {
            if (_ComponentList.ContainsKey(key))
                _ComponentList.Remove(key);
        }
                
        protected override void RenderComponent(SpriteBatch batch, GameTime time)
        {
            foreach (GUIComponent component in _ComponentList.Values)
                component.Render(batch, time);
        }
        protected override void SolveComponent(InputControl input, GameTime time)
        {
            foreach (GUIComponent component in _ComponentList.Values)
                component.Update(input, time);
        }
    }
}
